package com.gs.mybatismptest.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import cn.mybatis.mp.core.mvc.impl.ServiceImpl;
import cn.mybatis.mp.core.sql.executor.chain.QueryChain;
import com.gs.mybatismptest.entity.TbUser;
import com.gs.mybatismptest.mapper.UserMapper;
import com.gs.mybatismptest.service.UserService;
import com.gs.mybatismptest.vo.UserVo;
import org.apache.ibatis.solon.annotation.Db;
import org.noear.solon.annotation.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@Component
public class UserServiceImpl extends ServiceImpl implements UserService {

    public static Logger log = LoggerFactory.getLogger(UserServiceImpl.class);


    @Db  //因为只有一个数据源 所以可简写；如果多个，则：@Db("master")
    UserMapper userMapper;

    //获取这个
   /* @Db
    SqlSessionFactory sqlSessionFactory;*/

    @Override
    public UserVo queryByUserId(String id) {
        log.info("--------------------查询开始------------------");
        TimeInterval timer = DateUtil.timer();
        UserVo userVo =   QueryChain.of(userMapper)
                .select(UserVo.class)
                .from(TbUser.class)
                .eq(TbUser::getId,id)
                .returnType(UserVo.class)
                .get();
        log.info("查询消耗时间：" + timer.interval()+"毫秒");
        return userVo;
    }
}
